#include<iostream>
#include<list>
using namespace std;
int main(){
	int n,m,b,c,i;
	cin>>n>>m;
	list<int>a[n+1];
	for(i=1;i<=n;++i) a[i].push_back(i);
	while(m--){
		cin>>b>>c;
		if(b==c)continue;
		a[b].splice(a[b].end(),a[c]);
	}
	for(i=1;i<=n;++i){
		for(list<int>::iterator it=a[i].begin();it!=a[i].end();++it)
			cout<<(*it)<<" ";
		cout<<endl;
	}
	return 0;
}